<!--
Author: Quan Van Sinh
Email : sinhvnb@vietnambiz.com
Mobile: 0972405165
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Images manager</title>
        <link type="text/css" rel="stylesheet" href="styles/admin.css" />
        <link type="text/css" rel="stylesheet" href="styles/jquery.contextMenu.css" />
        <link type="text/css" rel="stylesheet" href="styles/jquery.alerts.css" media="screen"/>
        <script type="text/javascript" src="js/jquery.min.js"></script>
        <script type="text/javascript" src="js/jquery.MultiFile.pack.js"></script>
        <script type="text/javascript" src="js/jquery.contextMenu.js"></script>
        <script type="text/javascript" src="js/jquery.alerts.js"></script>
        <script type="text/javascript" src="js/common.js"></script>
        <script type="text/javascript">
            var imagePosition = '<?php echo $_REQUEST['position'];?>';
<?php $arrDir = explode('/', $_GET['dir']);?>
    d = new Date();
    var imageDir = '<?php echo $arrDir[0].'/'.$arrDir[1];?>';
    var module = '<?php echo $_GET['forModule'];?>';
    function toImages(value){
        if(imagePosition=='content'){
            if(window.opener.$("#38_textInput")){
                window.opener.$("#38_textInput").val(value);
            }else{
                window.opener.$("#45_textInput").val(value);
            }
        }else{
            if(module=='property'){
                var randNumber = rand(999,999999999);
                var thumbObjHtml = '<div id="'+randNumber+'"><input type="hidden" name="thumb[]" value="'+value+'"/><img id="imgDisplay" src="'+value+'" style="float:left;border:3px solid #CCC;margin-right:5px;margin-top:5px;width:87px;height:87px;" alt=""/><a title="Delete this image" class="removeImage" href="javascript:removeImage('+randNumber+');"/></div>';
                if(!strpos(window.opener.$("#propertyImagesThumb").html(), value)){
                    window.opener.$("#propertyImagesThumb").html(thumbObjHtml + window.opener.$("#propertyImagesThumb").html());
                    $("#alertInfo").hide('slow');
                    $("#alertInfo").html('<span style="color:green;">Thêm mới ảnh thành công!</span>');
                    $("#alertInfo").show('slow');
                    setTimeout("closeAlertMessages('alertInfo')",8000);
                }else{
                    $("#alertInfo").hide('slow');
                    $("#alertInfo").html('<span style="color:red;">Ảnh này đã được thêm rồi!</span>');
                    $("#alertInfo").show('slow');
                    setTimeout("closeAlertMessages('alertInfo')",8000);
                }
            }else{
                window.opener.document.getElementById('image').value = value;
                window.opener.document.getElementById('imgDisplay').src = value;
            }
        }
        if(module=='property' && imagePosition=='content'){
            this.close();
        }else if(module!='property'){
            this.close();
        }
    }
    function togleUpload(){
        $("#UploadImages").toggle('medium',function () {
            if($("#toggleText").html()=='Ẩn form upload ảnh'){
                $(".form_error").hide();
                $(".form_ok").hide();
                $("#toggleText").html('Hiện form upload ảnh');
            }else if($("#toggleText").html()=='Hiện form upload ảnh'){
                $(".form_error").hide();
                $(".form_ok").hide();
                $("#toggleText").html('Ẩn form upload ảnh');
            }
        });
    }
    function del(htmlObj){
        var loc = '<?php echo SITE_URL.get_string_url(array('delDir','action','filename')); ?>&action=del&delDir='+imageDir+'&filename='+htmlObj.attr('src');
        confirm_get("Bạn có thực sự muốn xóa ảnh này?",loc);
    }

    function imagesContextAction(){
        $(".imagesContextAction").contextMenu({
            menu: 'imagesContextAction'
        }, function(action, el, pos) {
            switch(action){
                case 'Chọn':
                    el.click();
                    break;
                case 'Xóa':
                    del(el);
                    break;
            }
        });
    }

    function closeAlertMessages(id){
        $("#"+id).hide('slow');
    }

    $(document).ready(function(){
        imagesContextAction();
    });
        </script>
    </head>
    <body bgcolor="#FFFFFF">
        <ul id="imagesContextAction" class="contextMenu">
            <li class="select"><a href="#select">Select</a></li>
            <li class="delete"><a href="#delete">Delete</a></li>
        </ul>
        <?php
        show_error();
        show_success();
        ?>

        <div id="UploadImages" style="padding-bottom:5px; display:none;">
            <form method="post" action="" id="form" name="formAddImages" style="padding-top: 10px" enctype="multipart/form-data">
                <div id="photo-add">
                    <div>
                        Chọn file upload: <input type="hidden" id="action" name="action" value="uploadImages"/>
                        <input type="file" class="multi" maxlength="10" name="images[]" id="images" accept="gif|jpg|jpeg|png"/><input type="submit"  value="Upload ảnh" name="addImagesSubmit" id="addImagesSubmit"/>
                    </div>
                    <div id="imageList"></div>
                </div>
            </form>
        </div>
        <div id="alertInfo" style="display:none;text-align:center;line-height:30px;"></div>
        <div class="breadCrumb" style="width:99%">
            <div style="float:left;width:300px;">
                <?php
                listDirPath();
                ?>
            </div>
            <span id="toggleText" style="float:right;cursor:pointer;color:blue;margin-top:5px;margin-right:15px;" onclick="togleUpload();">Hiện form upload ảnh</span>
        </div>
        <div id="imagesThumb" style="float:left;width:98%;margin:10px;">
            <?php
            listDir();
            ?>
        </div>
    </body>
</html>



